package io.chenglicun.common.trans.service.impl.dict;

import io.chenglicun.common.trans.core.TransField;
import io.chenglicun.common.trans.service.impl.TransRepository;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.Collections;
import java.util.List;
import java.util.Map;

import static java.util.stream.Collectors.toMap;

@Component
public class DictTransRepository implements TransRepository {

    @Autowired
    private ObjectProvider<DictLoader> dictLoaderProvider;

    @Override
    public Map<String, Object> getKeysMap(TransField transField, List<String> keys) {
        DictLoader dictLoader = dictLoaderProvider.getIfAvailable();
        if (dictLoader != null) {
            return keys.stream()
                    .collect(toMap(x -> x, dictLoader::loadDict));
        }
        return Collections.emptyMap();
    }

}
